package cn.com.darly.videoandroidpm.ui.registerfriend;

import android.os.Bundle;
import android.text.TextUtils;
import android.view.View;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.darly.common.ToastApp;
import com.darly.dview.framework.ContentBinder;
import com.darly.dview.framework.ViewsBinder;
import com.darly.dview.widget.camera.util.ImageLoaderUtil;
import com.darly.dview.widget.header.TitleView;

import java.util.LinkedHashMap;
import java.util.Map;

import cn.com.darly.videoandroidpm.R;
import cn.com.darly.videoandroidpm.base.BaseActivity;
import cn.com.darly.videoandroidpm.bean.FriendInfo;
import cn.com.darly.videoandroidpm.ui.biz.BeenFriendListener.BeenFriendInterface;
import cn.com.darly.videoandroidpm.ui.presenter.BeenFriendPresenter;
import cn.com.darly.videoandroidpm.widget.dialog.ImageLoadingDialog;

/**
 *  其他用戶添加本用戶為好友。這裡進行詳細信息展示
 * Copyright (c) 2017 Organization D.L. zhangyuhui All rights reserved.
 * @author  Darly/张宇辉/2018/4/19 10:49
 * @version  1.0/cn.com.darly.videoandroidpm
 */
@ContentBinder(R.layout.activity_been_friend)
public class BeenFriendActivity extends BaseActivity implements View.OnClickListener,BeenFriendInterface{
    @ViewsBinder(R.id.id_base_title)
    public TitleView id_base_title;
    //用户信息
    @ViewsBinder(R.id.id_user_info)
    private RelativeLayout id_user_info;
    @ViewsBinder(R.id.id_user_info_account)
    private TextView id_user_info_account;
    @ViewsBinder(R.id.id_user_info_realname)
    private TextView id_user_info_realname;
    @ViewsBinder(R.id.id_user_info_phone)
    private TextView id_user_info_phone;
    @ViewsBinder(R.id.id_user_info_icon)
    private ImageView id_user_info_icon;
    @ViewsBinder(R.id.id_user_info_image)
    private ImageView id_user_info_image;

    @ViewsBinder(R.id.id_been_friend_msg)
    private TextView id_been_friend_msg;
    ImageLoadingDialog dialog;
    FriendInfo friend;

    private BeenFriendPresenter presenter;

    @Override
    protected void initView(Bundle savedInstanceState) {
        friend = (FriendInfo) getIntent().getSerializableExtra("FriendInfo");
        id_base_title.setTitle("验证申请");
        presenter = new BeenFriendPresenter(this);
    }

    @Override
    protected void loadData() {
        id_user_info.setBackgroundResource(R.color.divider);
        if (!TextUtils.isEmpty(friend.getIcon())) {
            ImageLoaderUtil.getInstance().loadImage(friend.getIcon(), id_user_info_icon);
        } else {
            id_user_info_icon.setImageResource(R.mipmap.ic_setting_user_icon);
        }
        id_user_info_account.setVisibility(View.GONE);
        id_user_info_realname.setText(String.format("昵称：" + friend.getName()));
        id_user_info_phone.setText(String.format("手机："+ friend.getMobile()));
        id_user_info_image.setVisibility(View.GONE);
        id_been_friend_msg.setText(friend.getBackup());
        dialog = new ImageLoadingDialog(this);
        dialog.setContentView(R.layout.dialog_image);
        dialog.setCanceledOnTouchOutside(true);
    }

    @Override
    protected void initListener() {
        id_base_title.setLeftBackOneListener(R.mipmap.ic_title_back,this);
        id_base_title.setRightViewRightTextOneListener("通过",this);
        id_user_info_icon.setOnClickListener(this);
    }


    @Override
    public void onClick(View v) {
        switch (v.getId()){
            case R.id.title_view_back_img:
               finish();
                break;
            case R.id.id_user_info_icon:
                //点击前面用户图像
                dialog.setImageResouce(R.mipmap.ic_setting_user_icon);
                dialog.show();
                break;
            case R.id.title_view_ok:
                Map<String, String> params  = new LinkedHashMap<String, String>();
                params.put("friendId",friend.getUserid());
                presenter.aie(params);
                break;
            default:
                break;
        }

    }

    @Override
    public void onBeenFriendSuccess(Object code) {
        setResult(200);
        end();
    }

    @Override
    public void onBeenFriendFailed(String info) {
        ToastApp.showToast(info);
    }

    @Override
    public void end() {
        finish();
    }

    @Override
    public void setDisableClick() {

    }

    @Override
    public void setEnableClick() {

    }
}
